package application.common.util;


import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.ptr.IntByReference;

public class ZTScannerSDK {
	

	public interface ZT_SCA extends Library {
		
		ZT_SCA INSTANCE = (ZT_SCA) Native.loadLibrary("ZT_SCA",ZT_SCA.class);

		/// <summary>
		/// 打开设备
		/// </summary>
		/// <param name="lpCom">串口号：COM1:9600:E:8:1 </param>
		/// <param name="nHandle">打开设备标识</param>
		/// <param name="nFage">设备类型:
		/// 1-为斯普锐 SE2102
		/// 2-为 MOTOSE3307
		/// 3-为民德 ES46XX
		/// 4-为 ZT661/FM420/FM430/EM2037/EM2039
		/// 5-为北京微光二维码
		/// 6-为 FR20/FM30
		/// 7-为霍尼韦尔 N3680
		/// 8-为意锐 RE6110
		/// 9-为斯普锐 SE7130C
		/// </param>
		/// <returns>备注：允许重复打开设备，如果设备已经打开，直接返回成功。</returns>

		public int ZT_SCA_OpenDevice(String lpCom, IntByReference nHandle, int nFage);
		
		/// <summary>
		/// 自动检测开启设备
		/// </summary>
		/// <param name="nPort">输出串口号</param>
		/// <param name="nBaud">输出波特率</param>
		/// <param name="nHandle">打开设备标识 </param>
		/// <param name="nType">设备类型</param>
		/// <returns>0－成功；其他则失败（失败返回其错误码）</returns>
		public int ZT_SCA_AutoOpenDevice(int nPort, int nBaud, int nHandle, int nType);

		/// <summary>
		/// 关闭设备
		/// </summary>
		/// <param name="nHandle">设备标识</param>
		/// <returns>0－成功；其他则失败（失败返回其错误码）</returns>
		public int ZT_SCA_CloseDevice(int nHandle);

		/// <summary>
		/// 设备复位
		/// </summary>
		/// <param name="nHandle">设备标识</param>
		/// <returns>0－成功；其他则失败（失败返回其错误码）</returns>
		public int ZT_SCA_Reset(int nHandle);

		/// <summary>
		/// 获取设备状态
		/// </summary>
		/// <param name="nHandle">设备标识</param>
		/// <returns>0－成功；其他则失败（失败返回其错误码）</returns>
		public int ZT_SCA_GetStatus(int nHandle);

		/// <summary>
		/// 开始扫描
		/// </summary>
		/// <param name="nHandle">设备标识</param>
		/// <returns>0－成功；其他则失败（失败返回其错误码）</returns>
		public int ZT_SCA_Startup(int nHandle);

		/// <summary>
		/// 取扫描数据
		/// </summary>
		/// <param name="nHandle">设备标识</param>
		/// <param name="Data">输出条码数据</param>
		/// <returns>0－成功；其他则失败（失败返回其错误码）</returns>
		public int ZT_SCA_GetData(int nHandle, byte[] Data);

		/// <summary>
		/// 停止扫描
		/// </summary>
		/// <param name="nHandle">设备标识</param>
		/// <returns>0－成功；其他则失败（失败返回其错误码）</returns>
		public int ZT_SCA_Stop(int nHandle);

		/// <summary>
		/// 设置声音模式 - 只支持斯普锐 SE2102
		/// </summary>
		/// <param name="">设备标识</param>
		/// <param name="">模式(0 - 关闭声音 1 - 开启声音)</param>
		/// <returns>0－成功；其他则失败（失败返回其错误码）</returns>
		public int ZT_SCA_SetVoice(int nHandle, short Mode);

		/// <summary>
		/// 获取设备总数 只支持 MOTOSE3307
		/// </summary>
		/// <param name="nHandle">设备标识</param>
		/// <param name="devNum">输出设备总数</param>
		/// <returns>0－成功；其他则失败（失败返回其错误码）</returns>
		public int ZT_SCA_GetListDevice(int nHandle, int devNum);

		/// <summary>
		/// 设置设备号 只支持 MOTOSE3307
		/// </summary>
		/// <param name="nHandle">设备标识</param>
		/// <param name="devNum">设备号(0 为第 1 个设备，1 为第 2 个)</param>
		/// <returns></returns>
		public int ZT_SCA_SetListDevice(int nHandle, int devNum);

	}
	public static void main(String[] args) {
		IntByReference nHandle = new IntByReference();nHandle.setValue(0);
		int nRet = ZT_SCA.INSTANCE.ZT_SCA_OpenDevice("COM3:9600:E:8:1",nHandle,9);
		System.out.println(nRet);
	}
}
